package com.fenghongzhang.a1808;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

public class MyDialog extends Dialog {


    private static final String TAG = "MyDialog";
    private TextView title;
    private TextView message;
    private Button no;
    private Button yes;

    private String yesStr;




    //2
    private YesOnClickListener yesOnClickListener;

    public MyDialog(@NonNull Context context) {
        super(context);
    }

    //1
    public interface YesOnClickListener{
        void click();
    }

    //3
    public void setYesOnClickListener(YesOnClickListener yesOnClickListener) {
        this.yesOnClickListener = yesOnClickListener;
    }



    //1,接口
    public interface NoClickListener{
        void click();
    }

    //2,声明声明变量
    private NoClickListener noClickListener;

    //3,赋值
    public void setNoClickListener(NoClickListener noClickListener) {
        this.noClickListener = noClickListener;
    }


    public void setYesStr(String yesStr) {
        this.yesStr = yesStr;
    }

    private String titleStr;

    public void setTitleStr(String titleStr) {
        this.titleStr = titleStr;
    }

    private String msgStr;

    public void setMsgStr(String msgStr) {
        this.msgStr = msgStr;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cust_layout);

        /**
         * 1,设置中间的字符串
         * 2.让组件和字符串绑定
         */

        title = (TextView) findViewById(R.id.title);
        message = (TextView) findViewById(R.id.message);
        no = (Button) findViewById(R.id.no);
        yes = (Button) findViewById(R.id.yes);


        if(msgStr != null){
            message.setText(msgStr);
        }

        if(titleStr != null){
            title.setText(titleStr);
        }

        if(yesStr != null){
            yes.setText(yesStr);
        }
        
        
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "onClick: ");
                yesOnClickListener.click();
                //消失
                dismiss();
            }
        });

        //4
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                noClickListener.click();
                dismiss();
            }
        });


    }
}
